#ifndef API_SERVER_HELPER_H
#define API_SERVER_HELPER_H

#define ADD_CROW_ROUTE(application, path, method, outerFunction, innerFunction)\
    CROW_ROUTE(application, path)                                              \
        .methods(method)(                                                      \
            [this](const crow::request& request)                               \
            {                                                                  \
                return crow::response {                                        \
                    outerFunction(request.body, innerFunction)                 \
                };                                                             \
            }                                                                  \
        )

#define ADD_CROW_ROUTE_GET_IDS(application, innerFunction)                     \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/get_ids", "POST"_method,                         \
        Api::Server::getIdsCall, innerFunction                                 \
    )

#define ADD_CROW_ROUTE_GET_ELEMENTS(application, innerFunction)                \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/get_elements", "POST"_method,                    \
        Api::Server::getElementsCall, innerFunction                            \
    )

#define ADD_CROW_ROUTE_ADD_ELEMENT(application, innerFunction)                 \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/add_element", "POST"_method,                     \
        Api::Server::addElementCall, innerFunction                             \
    )

#define ADD_CROW_ROUTE_SET_ELEMENT(application, innerFunction)                 \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/set_element", "POST"_method,                     \
        Api::Server::setElementCall, innerFunction                             \
    )

#define ADD_CROW_ROUTE_DEL_ELEMENT(application, innerFunction)                 \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/del_element", "POST"_method,                     \
        Api::Server::delElementCall, innerFunction                             \
    )

#define ADD_CROW_ROUTE_HAS_CHANGES(application, innerFunction)                 \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/has_changes", "POST"_method,                     \
        Api::Server::hasChangesCall, innerFunction                             \
    )

#define ADD_CROW_ROUTE_LOGIN(application, innerFunction)                       \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/login", "POST"_method,                           \
        Api::Server::loginCall, innerFunction                                  \
    )

#define ADD_CROW_ROUTE_LOGOUT(application, innerFunction)                      \
    ADD_CROW_ROUTE(                                                            \
        application, "/api/v1/logout", "POST"_method,                          \
        Api::Server::logoutCall, innerFunction                                 \
    )

#endif // API_SERVER_HELPER_H
